package com.yiwyn.Creational.factory;

/**
 * 抽象工厂demo
 */
public class AbstractFactoryDemo {

    public static void main(String[] args) {

        DeviceAbstractFactory factory = new HuaweiDeviceFacotry();
        Phone phone = factory.createPhone();
        Laptap laptap = factory.createLaptap();
        phone.call();
        laptap.work();
    }


    /**
     * 手机
     */
    interface Phone {
        void call();
    }

    /**
     * 笔记本
     */
    interface Laptap {
        void work();
    }


    /**
     * 设备抽象工厂
     */
    interface DeviceAbstractFactory {

        Phone createPhone();

        Laptap createLaptap();
    }


    static class HuaweiPhone implements Phone {
        @Override
        public void call() {
            System.out.println("华为手机");
        }
    }

    static class IPhone implements Phone {

        @Override
        public void call() {
            System.out.println("苹果手机");
        }
    }


    static class HauweiLaptap implements Laptap {
        @Override
        public void work() {
            System.out.println("华为笔记本工作");
        }
    }

    static class MacBookLaptap implements Laptap {

        @Override
        public void work() {
            System.out.println("苹果笔记本");
        }
    }

    /**
     * 华为设备工厂
     */
    static class HuaweiDeviceFacotry implements DeviceAbstractFactory {

        @Override
        public Phone createPhone() {
            return new HuaweiPhone();
        }

        @Override
        public Laptap createLaptap() {
            return new HauweiLaptap();
        }
    }

    /**
     * 苹果设备工厂
     */
    static class AppleDeviceFactory implements DeviceAbstractFactory {

        @Override
        public Phone createPhone() {
            return new IPhone();
        }

        @Override
        public Laptap createLaptap() {
            return new MacBookLaptap();
        }
    }


}
